package com.labprog.oncapintada.persistencia;

import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * Data access object (DAO) for domain model class UsuUsuario.
 * @see com.labprog.oncapintada.persistencia.UsuUsuario
 * @author MyEclipse - Hibernate Tools
 */
public class UsuUsuarioDAO extends BaseHibernateDAO {

    private static final Log log = LogFactory.getLog(UsuUsuarioDAO.class);

	//property constants
	public static final String USU_NOMECOMPLETO = "usuNomecompleto";
	public static final String USU_RG = "usuRg";
	public static final String USU_CPF = "usuCpf";
	public static final String USU_TEL1 = "usuTel1";
	public static final String USU_TEL2 = "usuTel2";
	public static final String USU_EMAIL = "usuEmail";
	public static final String USU_SENHA = "usuSenha";
	public static final String USU_LOGIN = "usuLogin";

    
    public void save(UsuUsuario transientInstance) {
        log.debug("saving UsuUsuario instance");
        try {
            getSession().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(UsuUsuario persistentInstance) {
        log.debug("deleting UsuUsuario instance");
        try {
            getSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public UsuUsuario findById( java.lang.Integer id) {
        log.debug("getting UsuUsuario instance with id: " + id);
        try {
            UsuUsuario instance = (UsuUsuario) getSession()
                    .get("com.labprog.oncapintada.persistencia.UsuUsuario", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(UsuUsuario instance) {
        log.debug("finding UsuUsuario instance by example");
        try {
            List results = getSession()
                    .createCriteria("com.labprog.oncapintada.persistencia.UsuUsuario")
                    .add(Example.create(instance))
            .list();
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding UsuUsuario instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from UsuUsuario as model where model." 
         						+ propertyName + "= ?";
         Query queryObject = getSession().createQuery(queryString);
		 queryObject.setParameter(0, value);
		 return queryObject.list();
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
	}

	public List findByUsuNomecompleto(Object usuNomecompleto) {
		return findByProperty(USU_NOMECOMPLETO, usuNomecompleto);
	}
	
	public List findByUsuRg(Object usuRg) {
		return findByProperty(USU_RG, usuRg);
	}
	
	public List findByUsuCpf(Object usuCpf) {
		return findByProperty(USU_CPF, usuCpf);
	}
	
	public List findByUsuTel1(Object usuTel1) {
		return findByProperty(USU_TEL1, usuTel1);
	}
	
	public List findByUsuTel2(Object usuTel2) {
		return findByProperty(USU_TEL2, usuTel2);
	}
	
	public List findByUsuEmail(Object usuEmail) {
		return findByProperty(USU_EMAIL, usuEmail);
	}
	
	public List findByUsuSenha(Object usuSenha) {
		return findByProperty(USU_SENHA, usuSenha);
	}
	
	public List findByUsuLogin(Object usuLogin) {
		return findByProperty(USU_LOGIN, usuLogin);
	}
	
    public UsuUsuario merge(UsuUsuario detachedInstance) {
        log.debug("merging UsuUsuario instance");
        try {
            UsuUsuario result = (UsuUsuario) getSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(UsuUsuario instance) {
        log.debug("attaching dirty UsuUsuario instance");
        try {
            getSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(UsuUsuario instance) {
        log.debug("attaching clean UsuUsuario instance");
        try {
            getSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
}